package cn.ljp.shopComment.controller.controller;

import cn.cc.common.beanCopy.utils.BeanCopierUtil;
import cn.cc.common.result.utils.RestResult;
import cn.cc.common.result.utils.RestResultEmum;
import cn.ljp.shopComment.controller.dto.DeleteShopCommentDto;
import cn.ljp.shopComment.controller.dto.InsertShopCommentDto;
import cn.ljp.shopComment.controller.dto.SeleceShopCommentDto;
import cn.ljp.shopComment.controller.vo.DeleteShopCommentVo;
import cn.ljp.shopComment.controller.vo.InsertShopCommentVo;
import cn.ljp.shopComment.service.bo.DeleteShopCommentBo;
import cn.ljp.shopComment.service.bo.InsertShopCommentBo;
import cn.ljp.shopComment.service.bo.SeleceShopCommentBo;
import cn.ljp.shopComment.service.domain.DeleteShopCommentDo;
import cn.ljp.shopComment.service.domain.InsertShopCommentDo;
import cn.ljp.shopComment.service.domain.SeleceShopCommentDo;
import cn.ljp.shopComment.service.service.ShopCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述类
 *
 * @ClassName ShopCommentController
 * @Description TODO
 * @Author liu'jia'peng
 * @Date 2021/7/20 17:14
 * @Version 1.0
 */
@RestController
@RequestMapping("/shopCommentController")
public class ShopCommentController {
    @Autowired
    private ShopCommentService shopCommentService;

    /**
     * 描述方法
     *      新增评论   需要 用户id 商品id 评论内容 ，
     * @Author liu'jia'peng
     * @Date 2021/7/21 9:55
     * @Return
     * @Param
     */
    @PostMapping("/insertShopComment")
    public RestResult<InsertShopCommentVo> insertShopComment(InsertShopCommentDto dto){
        InsertShopCommentBo insertShopCommentBo = BeanCopierUtil.copyObj(dto, InsertShopCommentBo.class);
        InsertShopCommentDo insertShopCommentDo = shopCommentService.insertShopComment(insertShopCommentBo);
        InsertShopCommentVo insertShopCommentVo = new InsertShopCommentVo();
        insertShopCommentVo.setToken(insertShopCommentDo.getToken());
        if (RestResultEmum.SUCCESS.code.equals(insertShopCommentDo.getCode())){
            return new RestResult<InsertShopCommentVo>(RestResultEmum.SUCCESS.code,RestResultEmum.SUCCESS.msg,insertShopCommentVo);
        }
        return new RestResult<InsertShopCommentVo>(RestResultEmum.SAVE_ERROR.code,RestResultEmum.SAVE_ERROR.msg,insertShopCommentVo);
    }

    /**
     * 描述方法
     *         通过commentId 删除  评论
     * @Author liu'jia'peng
     * @Date 2021/7/21 10:55
     * @Return
     * @Param
     */
    @PostMapping("/deleteShopComment")
    public RestResult<DeleteShopCommentVo> deleteShopComment(DeleteShopCommentDto dto){
        DeleteShopCommentBo deleteShopCommentBo = BeanCopierUtil.copyObj(dto, DeleteShopCommentBo.class);
        DeleteShopCommentDo deleteShopCommentDo = shopCommentService.deleteShopComment(deleteShopCommentBo);
        DeleteShopCommentVo deleteShopCommentVo = new DeleteShopCommentVo();
        deleteShopCommentVo.setToken(deleteShopCommentDo.getToken());
        if (RestResultEmum.SUCCESS.code.equals(deleteShopCommentDo.getCode())){
            return new RestResult<DeleteShopCommentVo>(RestResultEmum.SUCCESS.code,RestResultEmum.SUCCESS.msg,deleteShopCommentVo);
        }
        return new RestResult<DeleteShopCommentVo>(RestResultEmum.DEL_ERROR.code,RestResultEmum.DEL_ERROR.msg,deleteShopCommentVo);
    }

    /**
     * 描述方法
     *       通过商品id 查询评论(父)
     * @Author liu'jia'peng
     * @Date 2021/7/21 11:06
     * @Return
     * @Param
     */
    @PostMapping("/seleceShopCommentFat")
    public RestResult<List<SeleceShopCommentDo>> seleceShopCommentFat(SeleceShopCommentDto dto){
        SeleceShopCommentBo seleceShopCommentBo = BeanCopierUtil.copyObj(dto, SeleceShopCommentBo.class);
        List<SeleceShopCommentDo> list = shopCommentService.seleceShopCommentFat(seleceShopCommentBo);
        return new RestResult<>(RestResultEmum.SUCCESS.code,RestResultEmum.SUCCESS.msg,list);
    }

    /**
     * 描述方法
     *      通过商品id 查询评论(子)
     * @Author liu'jia'peng
     * @Date 2021/7/21 12:24
     * @Return
     * @Param
     */
    @PostMapping("/seleceShopCommentSon")
    public RestResult<List<SeleceShopCommentDo>> seleceShopCommentSon(SeleceShopCommentDto dto){
        SeleceShopCommentBo seleceShopCommentBo = BeanCopierUtil.copyObj(dto, SeleceShopCommentBo.class);
        List<SeleceShopCommentDo> list = shopCommentService.seleceShopCommentSon(seleceShopCommentBo);
        return new RestResult<>(RestResultEmum.SUCCESS.code,RestResultEmum.SUCCESS.msg,list);
    }
}

